package textprocessing.datasources.enwikipedia;

import com.fasterxml.jackson.databind.JsonNode;
import common.dao.elastic.ElasticSearchDao;
import org.elasticsearch.action.index.IndexResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by julianzliu on 4/19/2017.
 */
public class IndexerEnWikiNews {

    static final Logger logger = LoggerFactory.getLogger(IndexerEnWikiNews.class);


    private ElasticSearchDao esDao = null;
    //private ObjectMapper mapper = null;
    private String host;
    private Integer port;

    public final String es_index = "enwikipedia";
    public final String es_type = "page";

    public final String es_context_index = "enwikipedia-context";
    public final String es_context_type = "context";

    public final String es_para_index = "enwikipedia-para";
    public final String es_para_type = "para";

    public final String es_doc_index = "enwikipedia-doc";
    public final String es_doc_type = "doc";





    public IndexerEnWikiNews(){
        this.host = "192.168.1.108";
        this.port = 29300;
        this.esDao = new ElasticSearchDao("elastic_cluster", this.host, this.port);
        //this.mapper = new ObjectMapper();
    }

    public ElasticSearchDao getEsDao(){
        return this.esDao;
    }


    public IndexResponse saveContextNode(JsonNode contextNode){
        return  this.esDao.indexAndResponse(this.es_context_index, this.es_context_type, null, (JsonNode)contextNode);
    }

    public IndexResponse saveParaNode(JsonNode contextNode){
        return  this.esDao.indexAndResponse(this.es_para_index, this.es_para_type, null, (JsonNode)contextNode);
    }

    public IndexResponse saveDocumentNode(JsonNode contextNode, String id){
        return  this.esDao.indexAndResponse(this.es_doc_index, this.es_doc_type, id, (JsonNode)contextNode);
    }

}
